/*
 * @lc app=leetcode.cn id=26 lang=typescript
 *
 * [26] 删除有序数组中的重复项
 */

// @lc code=start
function removeDuplicates(nums: number[]): number {
    if (nums.length === 0) return 0;
    let usedCursor = 0;
    let last: number | undefined = undefined;
    for (let index = 0; index < nums.length; index++) {
        const element = nums[index];
        if (last === undefined || element > last) {
            nums[usedCursor] = element;
            usedCursor++;
            last = element;
        }
    }
    nums.length = usedCursor;
    return usedCursor;
}
// @lc code=end
